# Maintainer: Sergej Pupykin <pupykin.s+arch@gmail.com>
# Maintainer: Daurnimator <daurnimator@archlinux.org>
# Maintainer: Caleb Maclennan <caleb@alerque.com>
# Contributor: Lucas Hermann Negri <kkndrox@gmail.com>

pkgbase=luaexpat
pkgname=(lua-expat lua51-expat lua52-expat lua53-expat)
pkgver=1.5.1
pkgrel=1
_rockrel=1
pkgdesc='SAX XML parser based on the Expat library'
arch=('loong64' 'x86_64')
url="https://github.com/lunarmodules/$pkgbase"
license=('MIT')
depends=(expat)
options=(debug)
makedepends=(lua
             lua51
             lua52
             lua53
             luarocks)
options=(debug)
_archive="$pkgbase-$pkgver"
_rock="$_archive-$_rockrel.linux-`uname -m`.rock"
_rockspec="$_archive-$_rockrel.rockspec"
source=("$url/archive/$pkgver/$_archive.tar.gz")
sha512sums=('45834b02d863a65c6de2ad3c5c671935ae512dd906233a647269438aeeb37c7bbd6e7166aefd8da72480b33e1aa79a86ed070ed8800a8e0f303ccc74918f3bb8')

build() {
	cd "$_archive"
	for LUAVER in 5.{1,2,3,4}; do
		luarocks --lua-version "$LUAVER" \
			CFLAGS="$CFLAGS -DLUA_C89_NUMBERS" \
			make --pack-binary-rock --deps-mode none -- "rockspecs/$_rockspec"
		install -Dm0644 -t "lua-$LUAVER/" "$_rock"
	done
}

_package() {
	cd "$_archive"
	depends+=("${pkgname%-*}")
	luarocks --lua-version "$1" --tree "$pkgdir/usr/" \
		install --deps-mode none --no-manifest -- "lua-$1/$_rock"
	install -Dm0644 -t "$pkgdir/usr/share/licenses/$pkgname/" LICENSE
}

package_lua-expat() {
	_package 5.4
}

package_lua53-expat() {
	_package 5.3
}

package_lua52-expat() {
	_package 5.2
}

package_lua51-expat() {
	replaces=(luaexpat)
	conflicts=(luaexpat)
	_package 5.1
}
